#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
typedef long long LL;

const int N = 2e6 + 10;

int que[N];

void solve(){
    int n;
    cin >> n;
    vector<int> arr((n + 10) * 2);
    for(int i = 1; i <= n; i ++) cin >> arr[i],arr[i + n] = arr[i];
    int hh = 0, tt = 0;
    int ans = 0;
    for(int i = 1; i <= n + n / 2 ; i ++)
    {
        if(hh <= tt &&  i - que[hh] > n / 2 ) hh ++;
        ans = max(ans,(long long)(arr[i] + i) + (arr[que[hh]] - que[hh]));
        while(hh <= tt && arr[que[tt]] - que[tt] <= arr[i] - i) tt --;
        que[++tt] = i;
    }
    cout << ans << endl;
}
signed main(){
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}


